package com.test.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.test.entity.News;

public class NewsDAO extends HibernateDaoSupport {
	public List<News> queryNews() {
		String hql = "from News";
		List<News> list = this.getHibernateTemplate().find(hql);
		return list;
	}

	public List<News> queryNewsdetail(int pageSize, int curpage) {
		Session session = this.getHibernateTemplate().getSessionFactory()
				.openSession();
		String hql = "from News order by newsTime desc";
		Query query = session.createQuery(hql);
		query.setFirstResult((curpage - 1) * pageSize);
		query.setMaxResults(pageSize);
		List<News> list = query.list();
		return list;
	}

	public Long queryRecordAmount() {
		List<Long> list = this.getHibernateTemplate().find(
				"select count(*) from News");
		Long object = null;
		if (list.size() > 0) {
			object = list.get(0);
		}
		return object;
	}

}
